package com.xingyang.controller;


import com.xingyang.controller.request.LinkGroupAddRequest;
import com.xingyang.controller.request.LinkUpdateRequest;
import com.xingyang.enums.BizCodeEnum;
import com.xingyang.service.LinkGroupService;
import com.xingyang.utils.JsonData;
import com.xingyang.vo.LinkGroupVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 信仰
 * @since 2023-12-10
 */
@RestController
@RequestMapping("/api/group/v1")
public class LinkGroupController {

    private LinkGroupService linkGroupService;

    @PostMapping("add")
    public JsonData add(@RequestBody LinkGroupAddRequest addRequest){
      int rows=  linkGroupService.add(addRequest);
      return rows==1?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_ADD_FAIL);
    }

    @DeleteMapping("del/{group_id}")
    public JsonData delete(@PathVariable("group_id") Long groupId){
        int rows=  linkGroupService.del(groupId);
        return rows==1?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_NOT_EXIST);
    }


    //查询详情
    @DeleteMapping("detail/{group_id}")
    public JsonData detail(@PathVariable("group_id") Long groupId){
        LinkGroupVO linkGroupVO=  linkGroupService.detail(groupId);
        return JsonData.buildSuccess(linkGroupVO);
    }


    //查询全部分组
    @GetMapping("list")
    public JsonData findUserAllLinkGroup(){
        List<LinkGroupVO> linkGroupVO=  linkGroupService.listAllGroup();
        return JsonData.buildSuccess(linkGroupVO);
    }

    //查询全部分组
    @GetMapping("update")
    public JsonData update(@RequestBody LinkUpdateRequest request){
        int rows=   linkGroupService.updateByid (request);
        return rows==1?JsonData.buildSuccess():JsonData.buildResult(BizCodeEnum.GROUP_OPER_FAIL);
    }

}

